//
//  MNDCreditorDetaiRootViewController.m
//  minidai
//
//  Created by 谭谭伟 on 2017/5/31.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDCreditorDetaiRootViewController.h"
#import "MNDFinaceDetailModel.h"
#import "MNDRiskAssessWebViewController.h"
#import "MNDLoginUserModel.h"
#import "MNDCreditorDetailViewController.h"

@interface MNDCreditorDetaiRootViewController ()

@property (nonatomic,strong) MNDCreditorDetailViewController *topVC;
@property (weak, nonatomic) IBOutlet UIView *headerView;

@end

@implementation MNDCreditorDetaiRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configContents];

    self.tableView.scrollEnabled = NO;
    if (kScreenHeight >= 812) {
        self.headerView.frame = CGRectMake(0, 0, kScreenWidth, 88);
    }

    //适配iOS11
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
//    [self loadData];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollCell:) name:@"scroll_up_or_down" object:nil];
    
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self initBackButtonItem];
  
}

- (void)initBackButtonItem {
    
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = kScreenWidth < 414? -10 : -15;
    
    UIImage *itemImage = [UIImage imageNamed:@"navi_back_btn_black"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage: itemImage
                                                             style: UIBarButtonItemStylePlain
                                                            target: self
                                                            action: @selector(backAction:)];
    
    
    [item setTintColor:kColorBlack];
    if (@available(iOS 11.0, *)) {
        self.navigationItem.leftBarButtonItem = item;
    } else {
        self.navigationItem.leftBarButtonItems = @[spaceItem, item];
    }
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];
}

#pragma mark - Action

- (void)backAction:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -加载数据

- (void)configContents {
    NSDictionary *dict = @{@"borrowCode":self.borrowCode,@"creditorCode":self.creditorCode};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"senderCreditorCode" object:dict];
}

- (void)scrollCell:(NSNotification *)notification {
    
    NSInteger scrollType = [notification.object integerValue];
    
    if (scrollType == 0) {
        
        [self.tableView scrollRectToVisible:CGRectMake(0, 0, kScreenWidth, kScreenHeight) animated:YES];
    } else {
        [self.tableView scrollToBottom];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    
    if (kScreenHeight >= 812) {
        //要减掉导航条的高度
        return screenHeight - 88;
    } else {
        //要减掉导航条的高度
        return screenHeight - 64;
    }
    
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"topDetaiVC"]) {
        self.topVC = [segue destinationViewController];
        self.topVC.discountStr = self.discountStr;
    }
}

@end
